/*	kd:
	
	This is the brand new edition of the main code. I think it's kinda pretty.
	I put in everything that I'd expect to find in the "main" part, like all the
	flow control and calls to draw. Mileage may vary.
	Anyway, enjoy the comments.
	
	*/

class Gc_Shop play {
	// kd: The UI.
	protected Gc_Shop_UiHandling		ui_handling;
	
	// kd: Screen spaces we're gonna need:
	protected vector2					window_resolution;
	protected vector2					sprite_resolution;
	protected vector2					text_resolution;
	protected vector2					sprite_to_window;
	
	// kd: Our good old ring.
	protected Gc_NormalFades			ring_offsets;
	protected Gc_Shop_InvLayout			ring_layout;
	protected Gc_Shop_CacheSmoothing	smoothing;
	
	// kd: Drawing the cursor / UI and its weird anims.
	protected Gc_Shop_CursorAnim		cursor_anim;
	protected Gc_Shop_ButtonDrawing		button_anim;
	
	// kd: Some additional graphics.
	protected Gcs_ButtonSprites			button_sprites;
	
	// kd: Handles the ring in / out animations
	protected Gc_Shop_TransitionAnim	transition_anim;
	protected Gc_Shop_TransitionAnim	old_transition_anim;
	
	// kd: Where are we?
	protected Gcs_ShopList				shop_list;
	protected Gc_Shop_Inv				current_shop;
	protected Gc_Shop_Inv				pending_shop;
	protected int						current_shop_index;
	protected int						pending_shop_index;
	protected Gc_Shop_Favorite			favorite;
	
	// kd: Most regrettable feature.
	protected Gc_ShopkeeperList			shopkeepers;
	protected Gc_Shop_KeeperControl		shopkeeper;
	protected Gcs_Shopkeeper			shopkeeper_mo;
	
	// kd: Text stuff.
	protected Gc_Shop_Messages			messages;
	protected Gc_Shop_LogMessages		log_messages;
	
	// kd: Who runs the show?
	protected PlayerInfo				player_info;
	protected bool						is_active;
	protected bool						is_quitting;
	protected bool						is_opening;
	protected bool						is_built;
	
	// kd: PARTICLE FX RETURNS
	protected Gc_Shop_Effects			special_fx;
	protected Gc_Rng					rng;
	
	// kd: The shop needs to show its animation while quitting, sooo...
	bool IsActive () const {
		return is_active;
	}
	
	// kd: This happens when the class gets built / constructed / whatever,
	// so do anything you need to do once here.
	bool OnBuild (PlayerInfo player, Gc_Rng rng_) {
		
		if(!rng_ || !ui_handling.Build()) {
			return false;
		}
		
		player_info = player;
		rng			= rng_;
		
		// kd: Get our buttons too. (These are the buttons used in the RING,
		// not in the UI!)
		button_sprites.Cache();
		
		// kd: This creates all the button animations with their sprites and
		// everything.
		button_anim.OnBuild(ui_handling);
		
		// kd: Let's make some space. The current shop is more than a pointer,
		// it actually kinda deep copies shops. That's to add handling for
		// hidden items.
		current_shop = new("Gc_Shop_Inv");
		
		ring_layout.Reposition();
		
		smoothing.ResetFade(fade_tics: 15);
		smoothing.ResetAutoUpdate();
		
		// kd: Oh wait we have to pass in our own rng because anything else
		// will desync everybody.
		special_fx.particle_fx.OnBuild(rng);
		special_fx.item_fx.OnBuild(rng);
		is_built = true;
		return true;
	}
	
	// kd: Do anything you need to do juuuuust before the shop opens here,
	// like anything related to resolutions.
	bool OnOpen (Gcs_ShopList shop_list_, Gc_ShopkeeperList shopkeepers_) {
		shop_list	= shop_list_;
		shopkeepers	= shopkeepers_;
		
		if(shop_list == NULL || !is_built) {
			return false;
		}
		
		// kd: Find some LANGUAGE nonsense.
		log_messages.Build();
		
		if(shop_list.ShopCount() < 1) {
			console.printf(log_messages.no_shops);
			return false;
		}
		
		// kd: We don't use GetAspectRatio here cuz that takes forced aspect
		// ratio into account, which causes AWFUL stretching.
		let window_aspect	= 1.0 * Screen.GetWidth() / Screen.GetHeight();
		
		// kd: The cursor moves inside of the window's space, not a scaled
		// screen space like the buttons.
		window_resolution	= 720 * (window_aspect, 1);
		ring_layout.InitForCursor(window_resolution);
		
		// kd: The sprites live in this consistent resolution.
		sprite_resolution	= 480 * (window_aspect, 1);
		text_resolution		= 480 * (window_aspect, 1);
		
		sprite_to_window	= (
			window_resolution.x / sprite_resolution.x,
			window_resolution.y / sprite_resolution.y);
		
		// kd: Bring on the cursor.
		cursor_anim.OnOpen(window_resolution, player_info, rng);
		
		// kd: Let's also make sure everything's coming in from outside.
		transition_anim.Reset();
		transition_anim.LayoutIn();
		transition_anim.ControlsIn();
		
		// kd: Scale our button animations to the resolution. It also has to
		// know about the positioning in the message box...
		button_anim.OnInit(sprite_resolution, ui_handling);
		
		// kd: Make sure the messages are positioned right.
		messages.Init(
			ui_handling,
			button_anim,
			text_resolution,
			sprite_resolution);
		
		// kd: This crazy back and forth... really makes you wanna cry tears of
		// utter joy.
		button_anim.OnUpDownInit(ui_handling, messages.DescriptionLines());
		
		// kd: Reset UI stuff like the mouse, too.
		ui_handling.OnInit(
			window_resolution,
			sprite_resolution,
			button_anim.sprites,
			button_anim.move_anim);
		
		// kd: Open into a viable shop.
		favorite.OnInit(
			shop_list,
			special_fx.particle_fx,
			button_anim,
			sprite_to_window);
		pending_shop_index	= favorite.OpeningShopIndex();
		pending_shop		= shop_list.At(pending_shop_index);
		
		// kd: I used a trick to make secret items. All items are stored in the
		// same array, but some are marked hidden. Item unlocks are for all
		// players, so you just have to remove that flag. All those without
		// flags are shown in this intermediate shop.
		// current_shop.CopyWithoutHiddenItems(pending_shop);
		
		// update: nvm, it doesn't make sense to do this here, because all
		// players are going to have the same unlocks, anyway.
		current_shop		= pending_shop;
		current_shop_index	= pending_shop_index;
		
		// kd: Now display everything and prepare for running NextState.
		is_active			= true;
		is_quitting			= false;
		is_opening			= true;
		OnInventoryLoad();
		
		// kd: Get a shopkeeper (might be THE SILENT SHOPKEEPER).
		shopkeeper.OnInit(shopkeepers);
		
		// kd: Other stuff:
		Gcs_ShopSounds.ShopStart();
		Gc_Shop_Entry.SendNetworkEvent("freezeplayer");
		special_fx.OnOpen();
		OnFxAnim();
		
		return true;
	}
	
	void OnClose () {
		is_quitting = true;
		
		// kd: Fade everything out nicely.
		ui_handling.SetCanSelectItems(false);
		transition_anim.LayoutOut();
		transition_anim.ControlsOut();
		cursor_anim.OnClose(rng);
		
		messages.ClearItemDescription();
		messages.ClearTalk();
		
		shopkeeper.Remove();
		shopkeeper.OnClose();
		
		Gc_Shop_Entry.SendNetworkEvent("resetfreeze");
		
		favorite.Save(current_shop_index);
		special_fx.Save();
	}
	
	// kd: When anim inwards starts (the buttons go outwards). This is where we
	// prepare the inventory shown.
	const max_scale_count       = 6;
	const min_scale_count       = 20;
	const max_button_scale      = 1.0;
	const min_button_scale      = 1.0 / 0.65;
	
	bool OnInventoryLoad () {
		// kd: First we need space. These should all be the same.
		let item_count = current_shop.ItemCount();
		ring_offsets.	ClearAndResize(item_count);
		ring_layout.	ClearAndResize(item_count);
		smoothing.		ClearAndResize(item_count);
		
		// kd: Prevent flicker.
		ring_layout.ClearPositions();
		
		// kd: Prevent stuff from being highlighted for no reason.
		ring_offsets.Reset();
		
		// kd: Then we fill it in.
		smoothing.cache.FillFromInventory(player_info, current_shop, button_sprites);
		smoothing.ForceTo(player_info, current_shop, button_sprites);
		
		// kd: Scale the inventory properly for the new item amount. The more
		// buttons there are, the smaller they should be, but they shouldn't
		// scale up or down infinitely, either.
		ring_layout.Rescale(clamp(
			Gc_Interpol.Line(
				item_count,
				max_scale_count,
				max_button_scale,
				min_scale_count,
				min_button_scale),
			max_button_scale,
			min_button_scale) );
		
		// kd: Some button animations dependent on user settings.
		OnFavoriteAnim();
		
		// kd: Now we can put some flashy stuff on screen, too.
		special_fx.LoadShopFx(current_shop);
		
		return true;
	}
	
	// kd: When the anim inwards finishes.
	bool OnInventoryLoadDone () {
		smoothing.AllowAutoUpdate(true);
		smoothing.ResetAutoUpdate();
		
		ui_handling.SetCanSelectItems(true);
		special_fx.BeginShopFx(ring_layout, window_resolution);
		
		Gcs_ShopSounds.ShopEnd();
		
		if(is_opening) {
			shopkeeper.Spawn();
			is_opening = false;
		}
		
		return true;
	}
	
	// kd: When the anim outwards starts.
	bool OnInventoryUnload () {
		smoothing.AllowAutoUpdate(false);
		ui_handling.SetCanSelectItems(false);
		transition_anim.LayoutOut();
		
		messages.ClearItemDescription();
		Gcs_ShopSounds.ShopStart();
		return true;
	}
	
	// kd: And when the outwards anim finishes.
	bool OnInventoryUnloadDone () {
		// kd: The player might press quit while the shop is in an animation
		// so in that case, it shouldn't go back in.
		if(!is_quitting) {
			transition_anim.LayoutIn();
			
			// kd: Let's load the next shop.
			// current_shop.CopyWithoutHiddenItems(pending_shop);
			current_shop		= pending_shop;
			current_shop_index	= pending_shop_index;
			OnInventoryLoad();
		}
		
		return true;
	}
	
	ui void HandleMouseMove (int dx, int dy) {
		ui_handling.mouse_input.NextState(dx, dy);
	}
	
	void NextState () {
		
		// kd: Do UI stuff. This outputs an item and an animation state for the
		// layout and its buttons.
		ui_handling.NextState(player_info, ring_layout);
		
		// kd: Animate the mouse and buttons.
		button_anim.NextState();
		cursor_anim.NextState();
	
		// kd: Cache this so we can tell when the shop anims finish.
		old_transition_anim.Copy(transition_anim);
		transition_anim.NextState();
		
		// kd: Switching shops and stuff.
		if(ui_handling.HasActed()) {
			let action_index = ui_handling.CurrentAction();
			
			button_anim.Click(action_index);
			
			switch(action_index) {
			case Gc_Shop_UiHandling.left:
				
				// kd: One shop to the left, but only if we have more than one.
				if(1 < shop_list.ShopCount()) {
					[pending_shop_index, pending_shop] =
						shop_list.PrevShop(pending_shop_index);
					OnInventoryUnload();
				}
				break;
				
			case Gc_Shop_UiHandling.right:
				if(1 < shop_list.ShopCount()) {
					[pending_shop_index, pending_shop] =
						shop_list.NextShop(pending_shop_index);
					OnInventoryUnload();
				}
				break;
				
			case Gc_Shop_UiHandling.scroll_up:
				messages.ScrollDescriptionUp();
				break;
				
			case Gc_Shop_UiHandling.scroll_down:
				messages.ScrollDescriptionDown();
				break;
				
			/*case Gc_Shop_UiHandling.poke_keeper:
				break;*/
			
			case Gc_Shop_UiHandling.favorite:
				
				// kd: This might set or unset favourite. We want the star and
				// particle fx to appear then.
				favorite.Set(current_shop_index);
				OnFavoriteAnim();
				
				// kd: Tell us what happened, too.
				if(favorite.IsFavorite(current_shop_index)) {
					Gcs_ShopSounds.Bookmark();
					console.printf(
						"\c[fire]%s Shop \c-%s!",
						current_shop.ShopName(),
						log_messages.bookmarked);
				}
				
				else {
					Gcs_ShopSounds.BookmarkRemove();
					console.printf(log_messages.bookmark_removed);
				}
				
				break;
			
			case Gc_Shop_UiHandling.fx:
				special_fx.Toggle();
				OnFxAnim();
				
				if(special_fx.IsShown()) {
					Gcs_ShopSounds.FxOn();
					console.printf(log_messages.fx_on);
				}
				
				else {
					Gcs_ShopSounds.FxOff();
					console.printf(log_messages.fx_off);
				}
				
				break;
				
			case Gc_Shop_UiHandling.switch_keeper:
				if(shopkeeper.RequestNext()) {
					shopkeeper.Remove();
				}
				
				break;
			}
		}
		
		if(transition_anim.IsLayoutInJustDone(old_transition_anim)) {
			OnInventoryLoadDone();
		}
		
		if(transition_anim.IsLayoutOutJustDone(old_transition_anim)) {
			OnInventoryUnloadDone();
		}
		
		// kd: Some experimental buttons I'll just implement here.
		/*if(
		ui_handling.IsHoveringButton() &&
		ui_handling.CurrentButton() == ui_handling.alpha_slider) {
			// let rel_pos = ui_handling.buttons.RelativeNormalPos();
			// total_alpha = 0.125 + rel_pos.x * 0.75;
		}*/
		
		// kd: Play some animations on the UI buttons.
		if(ui_handling.HasHoveredButton()) {
			button_anim.Hover(ui_handling.CurrentButton());
			Gcs_ShopSounds.Select();
		}
		
		if(ui_handling.HasDehoveredButton()) {
			button_anim.Dehover(ui_handling.PreviousButton());
		}
		
		// kd: Buying stuff and selecting items.
		if(ui_handling.HasHoveredItem()) {
			let current_item = ui_handling.CurrentItem();
			
			ring_offsets.ToEnd(current_item, tics: 13);
			messages.DisplayItem(current_shop, current_item);
			messages.DisplayTip(player_info, current_shop, current_item);
			Gcs_ShopSounds.SelectItem();
			Gc_Shop_ToWorld.SendNetworkEvent(
				"ShopkeeperReactToItemDehover",
				current_shop_index,
				current_item);
		}
		
		if(ui_handling.HasDehoveredItem()) {
			let previous_item = ui_handling.PreviousItem();
			
			ring_offsets.ToStart(ui_handling.PreviousItem(), tics: 26);
			Gc_Shop_ToWorld.SendNetworkEvent(
				"ShopkeeperReactToItemHover",
				current_shop_index,
				previous_item);
		}
		
		if(ui_handling.HasLeftRing()) {
			Gc_Shop_ToWorld.SendNetworkEvent("ShopkeeperReactLeaveRing");
		}
		
		if(ui_handling.HasTriedBuying(player_info)) {
			HandleBuying();
		}
		
		if(ui_handling.HasTriedEquipping(player_info)) {
			HandleEquipping();
		}
		
		// kd: Makes highlighting show up.
		ring_offsets.NextState();
		
		// kd: Makes the ring buttons fade their lamps and such.
		smoothing.NextState(player_info, current_shop, button_sprites);
		smoothing.NextAutoUpdate();
		
		if(smoothing.WantsAutoUpdate()) {
			smoothing.To(player_info, current_shop, button_sprites);
			smoothing.ResetAutoUpdate();
		}
		
		// kd: Rotates stuff on the screen.
		ring_layout.CacheOldPositions();
		
		let ring_anim_tics = transition_anim.duration_tics;
		
		if(transition_anim.IsLayoutAnimating()) {
			let layout_f = transition_anim.layout_t.StandardDelta(ring_anim_tics);
			ring_layout.NextFrame(layout_f);
		}
		
		// kd: Do animation stuff.
		ring_offsets.NextState();
		
		// kd: Type the text.
		messages.NextState();
		
		// kd: Update the particle fx. They only update when the shop is fully
		// opened. This allows you to place something like an opening explosion
		// on certain items. Everything else always updates.
		
		special_fx.NextItemFxState(ring_layout, window_resolution);
		special_fx.SpawnPosTo(ui_handling.mouse_input.Position());
		special_fx.NextExtraFxState();
		
		// kd: If we're leaving, wait till the animation ran out. Then we'll
		// sod off outta the shop.
		if(is_quitting && transition_anim.controls_t.IsDone()) {
			is_active = false;
		}
	}
	
	// kd: Here we handle buying and equipping separately for organisation.
	// The above is getting kinda long.
	protected void HandleBuying () {
		let current_item= ui_handling.CurrentItem();
		let result		= current_shop.BuyItem(player_info.mo, current_item);
		
		// kd: This'll notify the shopkeeper. They'll decide the rest.
		Gc_Shop_ToWorld.SendNetworkEvent(
			"ShopkeeperReactToBuy",
			current_shop_index,
			current_item,
			result);
		
		switch(result) {
		case Gc_Shop_Inv.EVENT_BUY_POOR:
			console.printf(log_messages.not_enough_money);
			Gcs_ShopSounds.Failure();
			break;
		
		case Gc_Shop_Inv.EVENT_BUY_CANT_CARRY:
			console.printf(log_messages.cant_carry);
			Gcs_ShopSounds.Failure();
			break;
		
		case Gc_Shop_Inv.EVENT_BUY_MAXED:
			console.printf(log_messages.got_enough);
			Gcs_ShopSounds.Failure();
			break;
		
		case Gc_Shop_Inv.EVENT_BUY_OKAY:
			console.printf(
				"%s \c[ice]%s\c-!",
				log_messages.you_got_it,
				current_shop.ItemTitle(current_item));
			Gcs_ShopSounds.Buy();
			
			// kd: Use the event handler, luke.
			Gc_Shop_ToWorld.SendNetworkEvent(
				"BuyItem",
				current_shop_index,
				current_item);
			
			// kd: Update what's shown, too.
			smoothing.To(player_info, current_shop, button_sprites);
			messages.DelayedDisplayTip(player_info, current_shop, current_item);
			
			// kd: BOOM BAYBEEEEEEH
			special_fx.BuyFx(current_shop, current_item);
			
			break;
		}
	}
	
	// kd: In retrospect, this is kind of a redundant way of doing that.
	protected void HandleEquipping () {
		let current_item= ui_handling.CurrentItem();
		let result		= current_shop.EquipItem(player_info.mo, current_item);
		
		// kd: This'll notify the shopkeeper. They'll decide the rest.
		Gc_Shop_ToWorld.SendNetworkEvent(
			"ShopkeeperReactToEquip",
			current_shop_index,
			current_item,
			result);
		
		switch(result) {
		case Gc_Shop_Inv.EVENT_EQUIP_NOT_YET:
			console.printf(log_messages.not_yet);
			Gcs_ShopSounds.Failure();
			break;
			
		case Gc_Shop_Inv.EVENT_EQUIP_CANT:
			console.printf(log_messages.cant_equip);
			Gcs_ShopSounds.Failure();
			break;
			
		case Gc_Shop_Inv.EVENT_EQUIP_DONT_HAVE:
			console.printf(log_messages.dont_have);
			Gcs_ShopSounds.Failure();
			break;
			
		case Gc_Shop_Inv.EVENT_EQUIP_ALREADY:
			console.printf(log_messages.already_equipped);
			Gcs_ShopSounds.Failure();
			break;
			
		case Gc_Shop_Inv.EVENT_EQUIP_OKAY_ON:
		case Gc_Shop_Inv.EVENT_EQUIP_OKAY_OFF:
		
			Gc_Shop_ToWorld.SendNetworkEvent(
				"EquipItem",
				current_shop_index,
				current_item);
			
			if(result == Gc_Shop_Inv.EVENT_EQUIP_OKAY_ON) {
				console.printf(String.Format(
					"\c[ice]%s \c-%s.",
					current_shop.ItemTitle(current_item),
					log_messages.activated));
			}
			
			else {
				console.printf(String.Format(
					"\c[ice]%s \c-%s.",
					current_shop.ItemTitle(current_item),
					log_messages.deactivated));
			}
			
			// kd: Update what's shown, too.
			smoothing.To(player_info, current_shop, button_sprites);
			messages.DelayedDisplayTip(player_info, current_shop, current_item);
			
			break;
		}
	}
	
	// kd: Particle fx toggling button anim:
	protected void OnFxAnim () {
		if(special_fx.IsShown()) {
			button_anim.Click(ui_handling.fx_on);
			button_anim.Hover(ui_handling.fx_on);
			button_anim.Hover(ui_handling.fx_off);
		}
		
		else {
			button_anim.Dehover(ui_handling.fx_on);
			button_anim.Dehover(ui_handling.fx_off);
		}
	}
	
	// kd: Bookmark button anim:
	protected void OnFavoriteAnim () {
		
		// kd: This displays a gold star with particles.
		if(favorite.IsFavorite(current_shop_index)) {
			favorite.fx_gen.SetHidden(false);
			button_anim.Click(ui_handling.favorite_on);
			button_anim.Hover(ui_handling.favorite_on);
			button_anim.Hover(ui_handling.favorite_off);
		}
		
		// kd: And this empties the button again.
		else {
			favorite.fx_gen.SetHidden(true);
			button_anim.Dehover(ui_handling.favorite_on);
			button_anim.Dehover(ui_handling.favorite_off);
		}
	}
	
	ui void DrawEverything (RenderEvent event) const {
		let t = event.fractic;
		
		// kd: Draw the entire layout.
		let ring_alpha = smoothing.fade_t.RenderStandardDelta(
			smoothing.FadeTics(),
			t);
		
		// kd: This makes the lighting up animations a biiiit smoother.
		ring_alpha = Gc_Interpol.trerpfast_unit(ring_alpha);
		
		ring_layout.Draw(
			smoothing,
			ring_offsets,
			button_sprites,
			ring_alpha:		ring_alpha,
			total_alpha:	0.777,
			t:				t);
		
		// let control_anim_tics	= transition_anim.duration_tics;
		let control_anim_f = transition_anim.controls_t.RenderStandardDelta(
			transition_anim.duration_tics,
			t);
		
		button_anim.NextFadeData(control_anim_f);
		
		// kd: Translucent sprites.
		button_anim.Draw(
			ui_handling.bottom_layer,
			ui_handling.extra_additive,
			sprite_resolution,
			t,
			style: STYLE_TRANSLUCENT);
		
		// kd: Text stuff.
		messages.Draw(text_resolution, t);
		
		// kd: Top layer buttons.
		button_anim.Draw(
			ui_handling.top_layer,
			ui_handling.top_layer_end,
			sprite_resolution,
			t,
			style: STYLE_ADD);
		
		// kd: Additive extra sprites.
		button_anim.Draw(
			ui_handling.extra_additive,
			ui_handling.total_sprite_count,
			sprite_resolution,
			t,
			style: STYLE_ADD);
		
		// kd: Shopkeeper's face, cursor and particle fx.
		button_anim.DrawShopkeeperFace(sprite_resolution, alpha: 0.777);
		cursor_anim.Draw(ui_handling, t);
		special_fx.Draw(window_resolution, t);
	}
	
	// Let the shopkeeper speak.
	void OnShopkeeperSpawn (Gcs_Shopkeeper shopkeeper_mo_) {
		shopkeeper_mo = shopkeeper_mo_;
		
		// kd: Determine some info that the UI and messages could use. This will
		// change item descriptions and the message box layout slightly.
		
		// Here, the shopkeeper gets 4 out of 9 lines for chatting, but only
		// if the author allows it. This way, you can make a completely visual
		// but silent shopkeeper.
		
		let comment_key	= shopkeeper_mo ? shopkeeper_mo.commentary_key : "nithor";
		let lines_shown	= shopkeeper_mo ? shopkeeper_mo.can_message ? 5 : 9 : 9;
		let name_key	= shopkeeper_mo ? shopkeeper_mo.shopkeeper_name : "";
		let color_in	= shopkeeper_mo ? shopkeeper_mo.talk_color1 : Font.CR_WHITE;
		let color_final	= shopkeeper_mo ? shopkeeper_mo.talk_color2 : Font.CR_ICE;
		
		messages.ClearItemDescription();
		messages.SetCommentary(
			comment_key,
			name_key,
			color_in,
			color_final,
			lines_shown);
		messages.ClearTalk();
		
		// kd: Realigns the bottom button visually and actually.
		button_anim.OnUpDownInit(ui_handling, lines_shown);
		ui_handling.OnInitButtons(
			window_resolution,
			sprite_resolution,
			button_anim.sprites,
			button_anim.move_anim);
			
		// kd: Show their face, too.
		button_anim.OnInitShopkeeper(shopkeeper_mo);
	}
	
	void OnShopkeeperRemoved () {
		if(!is_quitting) {
			shopkeeper.Spawn();
		}
	}
	
	// kd: type_speed = 5.0 / 3 would put 5 chars every 3 tics, but not all at
	// once, it's all nice and smooth.
	
	// This puts a message in the shopkeeper's console.
	void Talk (String msg, double type_speed = 1.0 / 3) {
		messages.DisplayTalk(msg, type_speed);
	}
	
	void StartTalkSound (String sound_name, int ticks_per_sound = 2) {
	}
	
	void TalkEndSound (String sound_name) {
	}
	
	void OnItemBind (uint item, uint bind) {
	}
}

// zs is great if you replace it with a bowl of cookies.